/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SWANLINK_FINANCE_COMMON_HILOG_WRAPPER_H
#define SWANLINK_FINANCE_COMMON_HILOG_WRAPPER_H

#include "hilog/log.h"
namespace SwanLink {
namespace Finance {
#define __FILENAME__            (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define __FORMATED(fmt, ...)    "[%{public}s] %{public}s# " fmt, __FILENAME__, __FUNCTION__, ##__VA_ARGS__
constexpr unsigned int FINANCE_DOMAIN = 0xD080100;

#define FINANCE_DOMAIN_BASE(base, offset)  (FINANCE_DOMAIN+32*(base)+(offset))
#define FINANCE_DOMAIN_COMMON(offset)  FINANCE_DOMAIN_BASE(0, offset)

#ifdef COMMON_HILOGF
#undef COMMON_HILOGF
#endif

#ifdef COMMON_HILOGE
#undef COMMON_HILOGE
#endif

#ifdef COMMON_HILOGW
#undef COMMON_HILOGW
#endif

#ifdef COMMON_HILOGI
#undef COMMON_HILOGI
#endif

#ifdef COMMON_HILOGD
#undef COMMON_HILOGD
#endif

enum COMMON_MODULE {
    COMMON_UTIL = 0,
    COMMON_KITS,
    COMMON_INNERKITS,
    COMMON_JS_NAPI,
    COMMON_SRV,
    COMMON_PLUGIN,
    COMMON_FDHANDLER,
    COMMON_TEST,
    COMMON_BUTT
};
// In order to improve performance, do not check the module range.

static constexpr OHOS::HiviewDFX::HiLogLabel COMMON_LABEL[COMMON_BUTT] = {
    {LOG_CORE, FINANCE_DOMAIN_COMMON(COMMON_UTIL),            "CommonUtils"},
    {LOG_CORE, FINANCE_DOMAIN_COMMON(COMMON_KITS),            "CommonKits"},
    {LOG_CORE, FINANCE_DOMAIN_COMMON(COMMON_INNERKITS),        "CommonInnerKits"},
    {LOG_CORE, FINANCE_DOMAIN_COMMON(COMMON_JS_NAPI),          "CommonJsNapi"},
    {LOG_CORE, FINANCE_DOMAIN_COMMON(COMMON_SRV),              "CommonSrv"},
    {LOG_CORE, FINANCE_DOMAIN_COMMON(COMMON_PLUGIN),            "PluginMgr"},
    {LOG_CORE, FINANCE_DOMAIN_COMMON(COMMON_FDHANDLER),         "FdHandler"},
    {LOG_CORE, FINANCE_DOMAIN_COMMON(COMMON_TEST),              "CommonTest"}
};

// Besides, make sure module is less than POWERMGR_MODULE_BUTT.
#define COMMON_HILOGF(module, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(COMMON_LABEL[module], __FORMATED(__VA_ARGS__))
#define COMMON_HILOGE(module, ...) (void)OHOS::HiviewDFX::HiLog::Error(COMMON_LABEL[module], __FORMATED(__VA_ARGS__))
#define COMMON_HILOGW(module, ...) (void)OHOS::HiviewDFX::HiLog::Warn(COMMON_LABEL[module], __FORMATED(__VA_ARGS__))
#define COMMON_HILOGI(module, ...) (void)OHOS::HiviewDFX::HiLog::Info(COMMON_LABEL[module], __FORMATED(__VA_ARGS__))
#define COMMON_HILOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(COMMON_LABEL[module], __FORMATED(__VA_ARGS__))

}  // namespace Finance
}  // namespace SwanLink

#endif  // SWANLINK_FINANCE_COMMON_HILOG_WRAPPER_H

